<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="box"></div>
    <script>
        const dom = document.getElementById('box');
        // 渲染引擎和js引擎不会反复切换
        for (let i = 0; i < 500000; i++) {
            foo(i);
        }
        // 
        function foo(i) {
            dom.innerText = '我来了' + i;
            new Promise(resolve => {
                resolve();
            }).then(res => {
                dom.innerText = '我来了' + i;
            });
            setTimeout(function() {
                dom.innerText = '我来了' + i;
            }, 0)
        }
    </script>
</body>

</html>